<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Git使用 | lilei</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/images/icons/logo.png">
    <link rel="apple-touch-icon" href="/images/icons/logo.png">
    <link rel="manifest" href="/manifest.json">
    <script type="text/javascript" src="/assets/js/load.js"></script>
    <meta name="description" content="个人网站">
    <meta name="twitter:title" content="Git使用">
    <meta name="twitter:description" content="">
    <meta name="twitter:card" content="summary">
    <meta name="twitter:url" content="http://www.lileiblog.xyz/IDE/Git%E4%BD%BF%E7%94%A8.html">
    <meta property="og:type" content="article">
    <meta property="og:title" content="Git使用">
    <meta property="og:description" content="">
    <meta property="og:url" content="http://www.lileiblog.xyz/IDE/Git%E4%BD%BF%E7%94%A8.html">
    <meta property="og:site_name" content="lilei">
    <meta itemprop="name" content="Git使用">
    <meta itemprop="description" content="">
    <meta name="theme-color" content="#3eaf7c">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="msapplication-TileImage" content="/images/icons/logo.png">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="keywords" content="lilei,vue,vuepress,vuepress-theme,theme,主题,vuepress主题,blog
        ,vuepress-blog,java,python,shell,sql,golang,script,shell script,nginx,windows,去广告,androd,google drive
        ,one drive,idea,eclipse,git,小程序">
    <meta name="referrer" content="never">
    
    <link rel="preload" href="/assets/css/0.styles.8932179b.css" as="style"><link rel="preload" href="/assets/js/app.269009d6.js" as="script"><link rel="preload" href="/assets/js/3.974b9720.js" as="script"><link rel="preload" href="/assets/js/15.0a4ff48f.js" as="script"><link rel="prefetch" href="/assets/js/10.5915e99b.js"><link rel="prefetch" href="/assets/js/11.ff732762.js"><link rel="prefetch" href="/assets/js/12.8bb86d91.js"><link rel="prefetch" href="/assets/js/13.18bde5b0.js"><link rel="prefetch" href="/assets/js/14.314fae34.js"><link rel="prefetch" href="/assets/js/16.ffaf1503.js"><link rel="prefetch" href="/assets/js/17.49a31a6e.js"><link rel="prefetch" href="/assets/js/18.7e6443bf.js"><link rel="prefetch" href="/assets/js/19.6880cc9a.js"><link rel="prefetch" href="/assets/js/20.1fb3f255.js"><link rel="prefetch" href="/assets/js/21.0cd39eea.js"><link rel="prefetch" href="/assets/js/22.392d85cb.js"><link rel="prefetch" href="/assets/js/23.f50adb15.js"><link rel="prefetch" href="/assets/js/24.43e324e1.js"><link rel="prefetch" href="/assets/js/25.e3663205.js"><link rel="prefetch" href="/assets/js/26.da141fb8.js"><link rel="prefetch" href="/assets/js/27.6c05235a.js"><link rel="prefetch" href="/assets/js/28.c124245a.js"><link rel="prefetch" href="/assets/js/29.d185870d.js"><link rel="prefetch" href="/assets/js/30.8587d422.js"><link rel="prefetch" href="/assets/js/31.dc382b56.js"><link rel="prefetch" href="/assets/js/32.20ba32e9.js"><link rel="prefetch" href="/assets/js/33.6ecd7de9.js"><link rel="prefetch" href="/assets/js/34.2b91c13a.js"><link rel="prefetch" href="/assets/js/35.66ed0733.js"><link rel="prefetch" href="/assets/js/36.ce7bca84.js"><link rel="prefetch" href="/assets/js/37.d00bb5ac.js"><link rel="prefetch" href="/assets/js/38.c3ecbb6f.js"><link rel="prefetch" href="/assets/js/39.308f4175.js"><link rel="prefetch" href="/assets/js/4.520f6ecc.js"><link rel="prefetch" href="/assets/js/40.f4b98bc2.js"><link rel="prefetch" href="/assets/js/41.95fae64f.js"><link rel="prefetch" href="/assets/js/42.fe4f877b.js"><link rel="prefetch" href="/assets/js/43.ca8f222e.js"><link rel="prefetch" href="/assets/js/44.4d4ee79e.js"><link rel="prefetch" href="/assets/js/45.79178b33.js"><link rel="prefetch" href="/assets/js/46.c3817d0b.js"><link rel="prefetch" href="/assets/js/47.b8252443.js"><link rel="prefetch" href="/assets/js/48.df9d5d3b.js"><link rel="prefetch" href="/assets/js/49.d812fdb2.js"><link rel="prefetch" href="/assets/js/5.f1a24a16.js"><link rel="prefetch" href="/assets/js/50.55cfcaa8.js"><link rel="prefetch" href="/assets/js/51.b8608b02.js"><link rel="prefetch" href="/assets/js/52.52c5e00d.js"><link rel="prefetch" href="/assets/js/53.3a9bd5fb.js"><link rel="prefetch" href="/assets/js/54.a4240c13.js"><link rel="prefetch" href="/assets/js/55.01c4b876.js"><link rel="prefetch" href="/assets/js/56.f29549a3.js"><link rel="prefetch" href="/assets/js/57.01438a04.js"><link rel="prefetch" href="/assets/js/58.29bb4626.js"><link rel="prefetch" href="/assets/js/59.e8b89408.js"><link rel="prefetch" href="/assets/js/6.8c478b39.js"><link rel="prefetch" href="/assets/js/60.bedb5381.js"><link rel="prefetch" href="/assets/js/61.bdfbe584.js"><link rel="prefetch" href="/assets/js/62.cb825d1a.js"><link rel="prefetch" href="/assets/js/63.a9516572.js"><link rel="prefetch" href="/assets/js/64.aa854ed7.js"><link rel="prefetch" href="/assets/js/65.285f883d.js"><link rel="prefetch" href="/assets/js/66.12849f37.js"><link rel="prefetch" href="/assets/js/67.c18b00e4.js"><link rel="prefetch" href="/assets/js/68.fa59daa9.js"><link rel="prefetch" href="/assets/js/69.e9d5dda4.js"><link rel="prefetch" href="/assets/js/7.cfb0d0ea.js"><link rel="prefetch" href="/assets/js/70.db126cce.js"><link rel="prefetch" href="/assets/js/71.6acb04cd.js"><link rel="prefetch" href="/assets/js/72.7ff0ab11.js"><link rel="prefetch" href="/assets/js/73.9a66da79.js"><link rel="prefetch" href="/assets/js/74.0a38a030.js"><link rel="prefetch" href="/assets/js/75.7b32dbb3.js"><link rel="prefetch" href="/assets/js/8.cb9c08e5.js"><link rel="prefetch" href="/assets/js/9.ad652cfe.js"><link rel="prefetch" href="/assets/js/vendors~flowchart.110a1065.js">
    <link rel="stylesheet" href="/assets/css/0.styles.8932179b.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/images/icons/logo.png" alt="lilei" class="logo"> <span class="site-name can-hide">lilei</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/Form/" class="nav-link">
  Form
</a></div><div class="nav-item"><a href="/IDE/" class="nav-link router-link-active">
  IDE
</a></div><div class="nav-item"><a href="/Java/" class="nav-link">
  Java
</a></div><div class="nav-item"><a href="/Other/" class="nav-link">
  Other
</a></div><div class="nav-item"><a href="/Python/" class="nav-link">
  Python
</a></div><div class="nav-item"><a href="/SQL/" class="nav-link">
  SQL
</a></div><div class="nav-item"><a href="/Shell/" class="nav-link">
  Shell
</a></div><div class="nav-item"><a href="/System/" class="nav-link">
  System
</a></div> <a href="https://github.com/woytu/notes-vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/Form/" class="nav-link">
  Form
</a></div><div class="nav-item"><a href="/IDE/" class="nav-link router-link-active">
  IDE
</a></div><div class="nav-item"><a href="/Java/" class="nav-link">
  Java
</a></div><div class="nav-item"><a href="/Other/" class="nav-link">
  Other
</a></div><div class="nav-item"><a href="/Python/" class="nav-link">
  Python
</a></div><div class="nav-item"><a href="/SQL/" class="nav-link">
  SQL
</a></div><div class="nav-item"><a href="/Shell/" class="nav-link">
  Shell
</a></div><div class="nav-item"><a href="/System/" class="nav-link">
  System
</a></div> <a href="https://github.com/woytu/notes-vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>IDE</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/IDE/" aria-current="page" class="sidebar-link">IDE</a></li><li><a href="/IDE/Chrome.html" class="sidebar-link">Chrome</a></li><li><a href="/IDE/Eclipse.html" class="sidebar-link">Eclipse</a></li><li><a href="/IDE/Git使用.html" class="active sidebar-link">Git使用</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/IDE/Git使用.html#flag" class="sidebar-link">Flag</a></li><li class="sidebar-sub-header"><a href="/IDE/Git使用.html#保存用户密码" class="sidebar-link">保存用户密码</a></li><li class="sidebar-sub-header"><a href="/IDE/Git使用.html#代理" class="sidebar-link">代理</a></li><li class="sidebar-sub-header"><a href="/IDE/Git使用.html#把空文件夹提交到仓库" class="sidebar-link">把空文件夹提交到仓库</a></li><li class="sidebar-sub-header"><a href="/IDE/Git使用.html#项目远程地址管理" class="sidebar-link">项目远程地址管理</a></li><li class="sidebar-sub-header"><a href="/IDE/Git使用.html#更改提交" class="sidebar-link">更改提交</a></li><li class="sidebar-sub-header"><a href="/IDE/Git使用.html#强制push本地仓库到远程" class="sidebar-link">强制push本地仓库到远程</a></li><li class="sidebar-sub-header"><a href="/IDE/Git使用.html#重置本地修改文件" class="sidebar-link">重置本地修改文件</a></li><li class="sidebar-sub-header"><a href="/IDE/Git使用.html#清除用户名密码" class="sidebar-link">清除用户名密码</a></li><li class="sidebar-sub-header"><a href="/IDE/Git使用.html#git恢复指定文件到指定版本" class="sidebar-link">git恢复指定文件到指定版本</a></li><li class="sidebar-sub-header"><a href="/IDE/Git使用.html#统计" class="sidebar-link">统计</a></li><li class="sidebar-sub-header"><a href="/IDE/Git使用.html#分支" class="sidebar-link">分支</a></li><li class="sidebar-sub-header"><a href="/IDE/Git使用.html#submodule与subtree" class="sidebar-link">SubModule与SubTree</a></li><li class="sidebar-sub-header"><a href="/IDE/Git使用.html#换行符与大文件处理" class="sidebar-link">换行符与大文件处理</a></li></ul></li><li><a href="/IDE/Git安装与问题.html" class="sidebar-link">Git安装与问题</a></li><li><a href="/IDE/Git服务.html" class="sidebar-link">Git服务</a></li><li><a href="/IDE/IDEA使用.html" class="sidebar-link">IDEA使用</a></li><li><a href="/IDE/IDEA插件.html" class="sidebar-link">IDEA插件</a></li><li><a href="/IDE/IDEA设置.html" class="sidebar-link">IDEA设置</a></li><li><a href="/IDE/TextEditor.html" class="sidebar-link">TextTditor</a></li><li><a href="/IDE/VisualStudioCode.html" class="sidebar-link">VisualStudioCode</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="git使用"><a href="#git使用" class="header-anchor">#</a> Git使用</h1> <p></p><div class="table-of-contents"><ul><li><a href="#flag">Flag</a></li><li><a href="#保存用户密码">保存用户密码</a></li><li><a href="#代理">代理</a></li><li><a href="#把空文件夹提交到仓库">把空文件夹提交到仓库</a></li><li><a href="#项目远程地址管理">项目远程地址管理</a></li><li><a href="#更改提交">更改提交</a></li><li><a href="#强制push本地仓库到远程">强制push本地仓库到远程</a></li><li><a href="#重置本地修改文件">重置本地修改文件</a></li><li><a href="#清除用户名密码">清除用户名密码</a></li><li><a href="#git恢复指定文件到指定版本">git恢复指定文件到指定版本</a></li><li><a href="#统计">统计</a></li><li><a href="#分支">分支</a></li><li><a href="#submodule与subtree">SubModule与SubTree</a></li><li><a href="#换行符与大文件处理">换行符与大文件处理</a></li></ul></div><p></p> <h2 id="flag"><a href="#flag" class="header-anchor">#</a> Flag</h2> <ul><li><a href="https://github.com/progit" target="_blank" rel="noopener noreferrer">https://github.com/progit<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <ul><li><a href="http://git-scm.com/book" target="_blank" rel="noopener noreferrer">http://git-scm.com/book<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/progit/progit2-zh" target="_blank" rel="noopener noreferrer">https://github.com/progit/progit2-zh<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/progit-cn" target="_blank" rel="noopener noreferrer">https://github.com/progit-cn<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <ul><li>Pro Git 中文版（第二版） <a href="https://progit.bootcss.com" target="_blank" rel="noopener noreferrer">https://progit.bootcss.com<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://codechina_dev.gitcode.host/progit2" target="_blank" rel="noopener noreferrer">https://codechina_dev.gitcode.host/progit2<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li></ul></li> <li><a href="https://github.com/apachecn/git-doc-zh" target="_blank" rel="noopener noreferrer">https://github.com/apachecn/git-doc-zh<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <ul><li><a href="https://git.apachecn.org" target="_blank" rel="noopener noreferrer">https://git.apachecn.org<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li> <li><a href="https://www.kancloud.cn/leviio/git/330946" target="_blank" rel="noopener noreferrer">常用命令 · git笔记 · 看云<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.moewah.com/archives/2292.html" target="_blank" rel="noopener noreferrer">Git 常用命令及使用详解 - 喵斯基部落<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>Git速查手册 <a href="https://github.com/arslanbilal/git-cheat-sheet" target="_blank" rel="noopener noreferrer">https://github.com/arslanbilal/git-cheat-sheet<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <ul><li><a href="https://www.rumosky.wiki/docs/learngit" target="_blank" rel="noopener noreferrer">https://www.rumosky.wiki/docs/learngit<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li> <li>Git的奇技淫巧: <a href="https://github.com/521xueweihan/git-tips" target="_blank" rel="noopener noreferrer">https://github.com/521xueweihan/git-tips<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>猴子都能懂的GIT入门: <a href="https://backlog.com/git-tutorial/cn/contents" target="_blank" rel="noopener noreferrer">https://backlog.com/git-tutorial/cn/contents<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://website-proxy.backlogtool.com/git-tutorial/cn/reference/git-svn.html" target="_blank" rel="noopener noreferrer">Git与Subversion的命令对比表<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/libgit2" target="_blank" rel="noopener noreferrer">https://github.com/libgit2<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>在线学 Git <a href="https://codechina_dev.gitcode.host/learn-git-branching" target="_blank" rel="noopener noreferrer">https://codechina_dev.gitcode.host/learn-git-branching<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><a href="https://blog.csdn.net/kunyus/article/details/93472646" target="_blank" rel="noopener noreferrer">Git 团队协作中常用术语 WIP PTAL CC LGTM 等解释<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><a href="/files/git-pull.bat">git-pull.bat</a></li> <li><a href="/files/git-pull.sh">git-pull.sh</a></li></ul> <p><strong><a href="/Other/编程规范.html#commit提交规范">Commit提交规范</a></strong></p> <blockquote><p><code>--global</code>代表全局，保存的配置在用户目录中，Windows在cmd中输入命令查看：<code>type %USERPROFILE%\.gitconfig</code></p></blockquote> <ul><li><code>git clone url --depth 1</code> 克隆最新一条提交记录</li> <li><code>git clone url --recursive</code> 递归克隆</li> <li><code>git fetch --unshallow</code> 完整克隆</li></ul> <h2 id="保存用户密码"><a href="#保存用户密码" class="header-anchor">#</a> 保存用户密码</h2> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">git</span> config --global --edit
<span class="token comment"># 设置项目个人邮箱</span>
<span class="token function">git</span> config --global user.email <span class="token string">&quot;your email&quot;</span>
<span class="token comment"># 设置项目个人用户名</span>
<span class="token function">git</span> config --global user.name  <span class="token string">&quot;your username&quot;</span>
<span class="token comment"># 永久保存凭证</span>
<span class="token function">git</span> config --global credential.helper store
</code></pre></div><blockquote><p>在<code>~/.gitconfig</code>中会自动在<code>[credential]</code>节点下添加<code>helper = store</code></p></blockquote> <blockquote><p>保存的账户密码在<code>~/.git-credentials</code>中</p></blockquote> <h2 id="代理"><a href="#代理" class="header-anchor">#</a> 代理</h2> <blockquote><p><code>git config --global https.sslverify false</code> 不验证SSL</p></blockquote> <p><strong>设置代理</strong></p> <ul><li>使用命令设置</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># socks5代理，如果是http则把socks5替换为http，https同理</span>
<span class="token function">git</span> config --global http.proxy <span class="token string">'socks5://127.0.0.1:10808'</span>
<span class="token function">git</span> config --global https.proxy <span class="token string">'socks5://127.0.0.1:10808'</span>
</code></pre></div><ul><li>编辑配置文件设置</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">vi</span> ~/.gitconfig
</code></pre></div><blockquote><p>在文件末尾添加</p></blockquote> <div class="language-ini extra-class"><pre class="language-ini"><code><span class="token header"><span class="token punctuation">[</span><span class="token section-name selector">http</span><span class="token punctuation">]</span></span>
<span class="token key attr-name">proxy</span> <span class="token punctuation">=</span> <span class="token value attr-value">socks5://127.0.0.1:10808</span>

<span class="token header"><span class="token punctuation">[</span><span class="token section-name selector">https</span><span class="token punctuation">]</span></span>
<span class="token key attr-name">proxy</span> <span class="token punctuation">=</span> <span class="token value attr-value">socks5://127.0.0.1:10808</span>
</code></pre></div><p><strong>取消代理</strong></p> <ul><li>命令</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">git</span> config --global --unset http.proxy
<span class="token function">git</span> config --global --unset https.proxy
</code></pre></div><ul><li>编辑配置文件取消代理，直接删除文件即可</li></ul> <h2 id="把空文件夹提交到仓库"><a href="#把空文件夹提交到仓库" class="header-anchor">#</a> 把空文件夹提交到仓库</h2> <blockquote><p>这个只能说是技巧不能说是方法，原理是在每个空文件夹新建一个.gitignore文件</p></blockquote> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">find</span> <span class="token builtin class-name">.</span> -type d -empty -exec <span class="token function">touch</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>/.gitignore <span class="token punctuation">\</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="项目远程地址管理"><a href="#项目远程地址管理" class="header-anchor">#</a> 项目远程地址管理</h2> <blockquote><p>见<code>项目目录/.git/config</code>中的<code>remote</code>节点，<code>origin</code>为默认远程节点名，可以自定义</p></blockquote> <ul><li>查看当前的远程地址</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">git</span> remote -v
</code></pre></div><ul><li>删除<code>origin</code>节点的远程地址</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">git</span> remote <span class="token function">rm</span> origin
<span class="token comment"># 或者</span>
<span class="token function">git</span> remote remove origin
</code></pre></div><ul><li>为<code>origin</code>节点添加远程地址</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">git</span> remote <span class="token function">add</span> origin 远程地址
</code></pre></div><ul><li>修改<code>origin</code>节点远程地址</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">git</span> remote set-url origin 远程地址
</code></pre></div><ul><li>为<code>origin</code>节点增加一个远程地址</li></ul> <blockquote><p>可同时拉取或推送到多个远程地址</p></blockquote> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">git</span> remote set-url --add origin 远程地址
</code></pre></div><ul><li>把当前分支与<code>origin</code>节点远程分支进行关联</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">git</span> push --set-upstream origin 分支名称
</code></pre></div><h2 id="更改提交"><a href="#更改提交" class="header-anchor">#</a> 更改提交</h2> <blockquote><p>如果commit注释写错了，只是想改一下注释</p></blockquote> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 查看提交文件，里面包含注释和变更内容</span>
<span class="token function">git</span> commit --amend
<span class="token comment"># 按v进入编辑模式，更改完成后按esc然后输入:qw! 保存</span>
</code></pre></div><ul><li>撤销提交</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># --mixed 默认参数，不删除工作空间改动代码，撤销commit，并且撤销git add . 操作</span>
<span class="token comment"># --soft 不删除工作空间改动代码，撤销commit，不撤销git add . </span>
<span class="token comment"># --hard 删除工作空间改动代码，撤销commit，撤销git add . </span>
<span class="token comment"># HEAD^的代表上一个版本，同HEAD~1(或HEAD@{1})，撤销2次commit，使用HEAD~2(或HEAD@{2})，以此类推</span>
<span class="token function">git</span> reset HEAD^
</code></pre></div><h2 id="强制push本地仓库到远程"><a href="#强制push本地仓库到远程" class="header-anchor">#</a> 强制push本地仓库到远程</h2> <blockquote><p>这种情况不会进行merge, 强制push后远程文件可能会丢失,不建议使用此方法</p></blockquote> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 将本地仓库文件push到远程仓库（-f代表强制 --force）</span>
<span class="token comment"># --allow-unrelated-histories 允许合并不相关的历史</span>
<span class="token function">git</span> push -u -f origin master
</code></pre></div><h2 id="重置本地修改文件"><a href="#重置本地修改文件" class="header-anchor">#</a> 重置本地修改文件</h2> <blockquote><p>如果有任何本地更改，将会丢失。无论是否有--hard选项，任何未被推送的本地提交都将丢失。
如果您有任何未被Git跟踪的文件(例如上传的用户内容)，这些文件将不会受到影响。</p></blockquote> <ul><li>在重置之前可以通过从master创建一个分支来维护当前的本地提交</li></ul> <blockquote><p>在此之后，所有旧的提交都将保存在新的分支中。然而，没有提交的更改(即使staged)将会丢失。确保存储和提交任何你需要的东西。</p></blockquote> <ul><li>执行重置</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 从远程下载最新的，而不尝试合并或rebase任何东西</span>
<span class="token function">git</span> fetch --all
<span class="token comment"># reset将主分支重置为本地commit的最新版本</span>
<span class="token comment"># --hard选项更改工作树中的所有文件以匹配origin/&lt;branch_name&gt;中的文件</span>
<span class="token function">git</span> reset --hard origin/<span class="token operator">&lt;</span>branch_name<span class="token operator">&gt;</span>
<span class="token comment"># 拉取远端最新代码</span>
<span class="token function">git</span> pull
</code></pre></div><div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 暂时忽略对文件做的修改</span>
<span class="token function">git</span> update-index --assume-unchanged 路径
<span class="token comment"># 重新标识对文件做的修改</span>
<span class="token function">git</span> update-index --no-assume-unchanged 路径
</code></pre></div><h2 id="清除用户名密码"><a href="#清除用户名密码" class="header-anchor">#</a> 清除用户名密码</h2> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">git</span> config --system --unset credential.helper
</code></pre></div><h2 id="git恢复指定文件到指定版本"><a href="#git恢复指定文件到指定版本" class="header-anchor">#</a> git恢复指定文件到指定版本</h2> <ul><li>查看commit历史，并复制需要回退版本的hash</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 或者git reflog show</span>
<span class="token function">git</span> log 文件名
</code></pre></div><ul><li>恢复</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">git</span> checkout 复制的hash值 文件名
</code></pre></div><ul><li>删除包括历史</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">git</span> filter-branch --force --index-filter <span class="token string">&quot;git rm --cached --ignore-unmatch src/main/java/com/bajins/demo/xxx.java&quot;</span> <span class="token punctuation">\</span>
  --prune-empty --tag-name-filter <span class="token function">cat</span> -- --all
</code></pre></div><h2 id="统计"><a href="#统计" class="header-anchor">#</a> 统计</h2> <ul><li>查看git上的个人代码量</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">git</span> log --author<span class="token operator">=</span><span class="token string">&quot;用户名&quot;</span> --pretty<span class="token operator">=</span>tformat: --numstat <span class="token operator">|</span> <span class="token function">awk</span> <span class="token string">'{ add += $1; subs += $2; loc += $1 - $2 } END \
  { printf &quot;added lines: %s, removed lines: %s, total lines: %s\n&quot;, add, subs, loc }'</span> -
</code></pre></div><ul><li>统计每个人增删行数</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">git</span> log --format<span class="token operator">=</span><span class="token string">'%aN'</span> <span class="token operator">|</span> <span class="token function">sort</span> -u <span class="token operator">|</span> <span class="token keyword">while</span> <span class="token builtin class-name">read</span> name<span class="token punctuation">;</span> <span class="token keyword">do</span> <span class="token builtin class-name">echo</span> -en <span class="token string">&quot;<span class="token variable">$name</span><span class="token entity" title="\t">\t</span>&quot;</span><span class="token punctuation">;</span> <span class="token function">git</span> log --author<span class="token operator">=</span><span class="token string">&quot;<span class="token variable">$name</span>&quot;</span> <span class="token punctuation">\</span>
  --pretty<span class="token operator">=</span>tformat: --numstat <span class="token operator">|</span> <span class="token function">awk</span> <span class="token string">'{ add += $1; subs += $2; loc += $1 - $2 } END { printf &quot;added lines: %s, \
  removed lines: %s, total lines: %s\n&quot;, add, subs, loc }'</span> -<span class="token punctuation">;</span> <span class="token keyword">done</span>
</code></pre></div><div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 查看仓库提交者排名前五</span>
<span class="token function">git</span> log --pretty<span class="token operator">=</span><span class="token string">'%aN'</span> <span class="token operator">|</span> <span class="token function">sort</span> <span class="token operator">|</span> <span class="token function">uniq</span> -c <span class="token operator">|</span> <span class="token function">sort</span> -k1 -n -r <span class="token operator">|</span> <span class="token function">head</span> -n <span class="token number">5</span>
<span class="token comment"># 贡献值统计</span>
<span class="token function">git</span> log --pretty<span class="token operator">=</span><span class="token string">'%aN'</span> <span class="token operator">|</span> <span class="token function">sort</span> -u <span class="token operator">|</span> <span class="token function">wc</span> -l
<span class="token comment"># 提交数统计</span>
<span class="token function">git</span> log --oneline <span class="token operator">|</span> <span class="token function">wc</span> -l
<span class="token comment"># 添加或修改的代码行数</span>
<span class="token function">git</span> log --stat<span class="token operator">|</span>perl -ne <span class="token string">'END { print $c } $c += $1 if /(\d+) insertions/'</span>
<span class="token comment"># 比较远端和本地分支</span>
<span class="token function">git</span> <span class="token function">diff</span> master origin/master
</code></pre></div><ul><li>统计文件的改动</li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">git</span> <span class="token function">diff</span> --stat master origin/master
<span class="token comment"># 执行一次git fetch origin xxx，那当下最新版本的commit会存在FETCH_HEAD中</span>
<span class="token function">git</span> <span class="token function">diff</span> HEAD FETCH_HEAD

<span class="token function">git</span> pull --dry-run <span class="token operator">|</span> <span class="token function">grep</span> -q -v <span class="token string">'Already up-to-date.'</span> <span class="token operator">&amp;&amp;</span> <span class="token assign-left variable">changed</span><span class="token operator">=</span><span class="token number">1</span>
<span class="token function">git</span> log HEAD<span class="token punctuation">..</span>.origin/master --oneline
<span class="token function">git</span> log -p master<span class="token punctuation">..</span>origin/master
</code></pre></div><ul><li>本地与远程的差集</li></ul> <blockquote><p>显示远程有而本地没有的<code>commit</code>信息</p></blockquote> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">git</span> log master<span class="token punctuation">..</span>origin/master
</code></pre></div><h2 id="分支"><a href="#分支" class="header-anchor">#</a> 分支</h2> <ul><li>查看本地分支<code>git branch</code></li> <li>查看远程分支<code>git branch -r</code></li> <li>查看所有分支<code>git branch -a</code></li> <li>本地创建新的分支<code>git branch [branch name]</code></li> <li>切换到新的分支<code>git checkout [branch name]</code></li> <li>创建+切换分支<code>git checkout -b [branch name]</code></li> <li>推送到指定分支<code>git push origin [branch name]</code></li> <li>删除本地分支<code>git branch -d [branch name]</code></li> <li>删除远程分支,分支名前的冒号代表删除<code>git push origin :[branch name]</code></li></ul> <h2 id="submodule与subtree"><a href="#submodule与subtree" class="header-anchor">#</a> SubModule与SubTree</h2> <ul><li><a href="https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E5%AD%90%E6%A8%A1%E5%9D%97" target="_blank" rel="noopener noreferrer">Git - 子模块<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li>submodule只存在引用，代码Pull和Push都只能和 被依赖的项目关联。类似于引用</li> <li>subtree直接克隆被依赖项目，代码Pull和Push根据需要和主项目或被依赖项目关联。类似于拷贝</li></ul> <table><thead><tr><th>/</th> <th>submodule</th> <th>subtree</th> <th>结果</th></tr></thead> <tbody><tr><td>远程仓库空间占用</td> <td>submodule只是引用，基本不占用额外空间</td> <td>子模块copy，会占用较大的额外空间</td> <td>submodule占用空间较小，略优</td></tr> <tr><td>本地空间占用</td> <td>可根据需要下载</td> <td>会下载整个项目</td> <td>所有模块基本都要下载，二者差异不大</td></tr> <tr><td>仓库克隆</td> <td>克降后所有子模块为空，需要注册及更新，同时更新后还需切换分支</td> <td>克隆之后即可使用</td> <td>submodule步骤略多，subtree占优</td></tr> <tr><td>更新本地仓库</td> <td>更新后所有子模块后指向最后一次提交，更新后需要重新切回分支，所有子模块只需一条更新语句即可</td> <td>所有子模块需要单独更新</td> <td>各有优劣，相对subtree更好用一些</td></tr> <tr><td>提交本地修改</td> <td>只需关心子模块即可，子模块的所有操作与普通git项目相同</td> <td>提交执行命令相对复杂一些</td> <td>submodule操作更简单，submodule占优</td></tr></tbody></table> <ul><li><code>git submodule add 链接 路径</code> 添加子模块，路径建议使用<code>_</code></li> <li><code>git submodule init</code> 初始化子模块</li> <li><code>git submodule update</code> 下载子模块源码</li> <li><code>git submodule update --init --recursive</code> 递归下载子模块的源码，并初始化</li> <li><code>git submodule foreach 'git checkout -f'</code> git强制更新所有submodule</li> <li><code>git pull</code> 把子模块看作单独的仓库，进入到子模块目录下，更新submodule，拉取后项目有需要提交的更新</li> <li><code>git clone url --recurse-submodules</code> 递归地将项目中所有子模块的代码拉取</li></ul> <p><strong>删除子模块</strong></p> <ul><li><code>vim .gitmodules</code> 移除子模块的索引信息</li> <li><code>git submodule deinit</code> 删除<code>.git/config</code>中的模块信息，加上参数<code>--force</code>子模块工作区内即使有本地的修改，也会被移除</li> <li><code>rm -rf 模块文件夹</code> 删除子模块目录文件</li> <li><code>rm -rf .git/modules/模块名</code> 移除子模块的其他信息</li> <li><code>git rm --cached 模块名</code> 删除缓存，提示<code>fatal: pathspec 'xxxxx' did not match any files</code> 说明删除干净了</li></ul> <h2 id="换行符与大文件处理"><a href="#换行符与大文件处理" class="header-anchor">#</a> 换行符与大文件处理</h2> <ul><li><a href="/Shell/#行尾序列">行尾序列（换行符）</a></li> <li><a href="https://segmentfault.com/a/1190000013973362" target="_blank" rel="noopener noreferrer">Git处理换行符问题<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://docs.github.com/cn/free-pro-team@latest/github/using-git/configuring-git-to-handle-line-endings" target="_blank" rel="noopener noreferrer">为单个仓库或全局配置 Git 处理行结束符<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li>当你在签出文件时，将 UNIX 换行符（LF）替换为 Windows 的换行符（CRLF）；</li> <li>当你在提交文件时，将 CRLF 替换为 LF。</li></ul> <blockquote><p>如果提交的文件是一个 包含中文字符的UTF-8文件，那么这个“换行符自动转换”功能在提交时不是每次都生效，
尤其是文件中出现中文字符后有换行符时（但签出时的转换处理没有问题）</p></blockquote> <p><strong>gitattributes</strong></p> <ul><li>为单个仓库设置 <a href="https://git-scm.com/docs/gitattributes" target="_blank" rel="noopener noreferrer">https://git-scm.com/docs/gitattributes<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://git-scm.com/book/zh/v2/%E8%87%AA%E5%AE%9A%E4%B9%89-Git-Git-%E5%B1%9E%E6%80%A7" target="_blank" rel="noopener noreferrer">8.2 自定义 Git - Git 属性<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://git.apachecn.org/#/docs/39" target="_blank" rel="noopener noreferrer">gitattributes<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><a href="https://github.com/topics/gitattributes" target="_blank" rel="noopener noreferrer">https://github.com/topics/gitattributes<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <ul><li><a href="https://github.com/gitattributes" target="_blank" rel="noopener noreferrer">https://github.com/gitattributes<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/alexkaratarakis/gitattributes" target="_blank" rel="noopener noreferrer">https://github.com/alexkaratarakis/gitattributes<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li></ul> <ul><li><code>text</code> <ul><li><code>linguist-language</code> 设置语言</li> <li><code>working-tree-encoding</code> 设置字符集编码</li> <li><code>eol</code> 设置换行符（<code>crlf</code>、<code>lf</code>）</li></ul></li> <li><code>-text</code></li> <li><code>text=string</code></li> <li><code>text=auto</code> 让git自行处理左边匹配的文件使用何种换行符格式，这是默认选项。</li> <li>未声明，通常不出现该属性即可</li> <li><code>!text</code> 为了覆盖其他文件中的声明，效果同上</li> <li><code>binary</code> 指定为二进制文件，不应该对其中的换行符进行改变。和<code>-text -diff</code>等价</li></ul> <ul><li><a href="https://github.com/woytu/notes-vuepress/blob/master/.gitattributes" target="_blank" rel="noopener noreferrer">.gitattributes示例文件<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 生成.gitattributes文件</span>
<span class="token builtin class-name">echo</span> <span class="token string">&quot;* text=auto&quot;</span> <span class="token operator">&gt;</span>.gitattributes
<span class="token comment"># 重新规范化所有被git管理的文件</span>
<span class="token function">git</span> <span class="token function">add</span> --renormalize <span class="token builtin class-name">.</span>
<span class="token comment"># 显示将被规范化的文件</span>
<span class="token function">git</span> status
<span class="token comment"># 提交</span>
<span class="token function">git</span> commit -m <span class="token string">&quot;Introduce end-of-line normalization&quot;</span>
</code></pre></div><ul><li><a href="https://github.com/editorconfig" target="_blank" rel="noopener noreferrer">https://github.com/editorconfig<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <code>.editorconfig</code>中设置<code>end_of_line = lf</code></li> <li><a href="https://github.com/axvr/ascribe.vim" target="_blank" rel="noopener noreferrer">https://github.com/axvr/ascribe.vim<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <p><strong>全局为所有仓库设置</strong></p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># windows 下是 autocrlf</span>

<span class="token comment"># 提交时转换为LF，检出时转换为CRLF</span>
<span class="token function">git</span> config --global core.autocrlf <span class="token boolean">true</span>

<span class="token comment"># 提交时转换为LF，检出时不转换</span>
<span class="token function">git</span> config --global core.autocrlf input

<span class="token comment"># 推荐，项目中指定了换行，则在任何平台都只用一种换行 \n</span>
<span class="token comment"># 提交检出均不转换</span>
<span class="token function">git</span> config --global core.autocrlf <span class="token boolean">false</span>

<span class="token comment"># SafeCRLF</span>

<span class="token comment"># 推荐，拒绝提交包含混合换行符的文件</span>
<span class="token function">git</span> config --global core.safecrlf <span class="token boolean">true</span>

<span class="token comment"># 允许提交包含混合换行符的文件</span>
<span class="token function">git</span> config --global core.safecrlf <span class="token boolean">false</span>

<span class="token comment"># 提交包含混合换行符的文件时给出警告</span>
<span class="token function">git</span> config --global core.safecrlf warn

<span class="token comment">#设置行结束符的类型为lf</span>
<span class="token function">git</span> config --global core.eol lf

<span class="token comment">#设置行结束符的类型为crlf</span>
<span class="token function">git</span> config --global core.eol crlf

<span class="token comment">#设置行结束符的类型为native, native是指平台默认的行结束符。默认的类型是native</span>
<span class="token function">git</span> config --global core.eol native


<span class="token comment"># 该命令表示提交命令的时候使用utf-8编码集提交</span>
<span class="token function">git</span> config --global i18n.commitencoding utf-8
<span class="token comment"># 该命令表示日志输出时使用utf-8编码集显示</span>
<span class="token function">git</span> config --global i18n.logoutputencoding utf-8
<span class="token comment"># 设置LESS字符集为utf-8</span>
<span class="token builtin class-name">export</span> <span class="token assign-left variable">LESSCHARSET</span><span class="token operator">=</span>utf-8
</code></pre></div><p><strong>Git LFS</strong></p> <ul><li>对大型文件进行版本控制 <a href="https://github.com/git-lfs" target="_blank" rel="noopener noreferrer">https://github.com/git-lfs<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <ul><li><a href="https://git-lfs.github.com" target="_blank" rel="noopener noreferrer">https://git-lfs.github.com<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li></ul> <blockquote><p>Git LFS（Large File Storage, 大文件存储）可以把指定的任意文件存在 Git 仓库之外，
而在 Git 仓库中用一个占用空间 1KB 不到的文本指针，可以减小 Git 仓库本身的体积来代替的小工具。</p></blockquote> <blockquote><p>git每次保存diff，一些大文件发生变化时，整个仓库就会增加很大的体积，导致clone和pull的数据量大增。
git push的时候，git lfs会截取要管理的大文件，并将其传至git lfs的服务器中，从而减小仓库的体积。</p></blockquote> <ul><li><code>git lfs track &quot;*.gz&quot;</code> 添加文件到<code>.gitattributes</code>追踪记录文件中</li> <li><code>git lfs ls-files</code> 显示当前提交后跟踪的文件列表</li> <li><code>git lfs clone</code> 克隆追踪的文件</li></ul></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/woytu/notes-vuepress/edit/master//IDE/Git使用.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2021-07-12 19:45:40</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/IDE/Eclipse.html" class="prev">
        Eclipse
      </a></span> <span class="next"><a href="/IDE/Git安装与问题.html">
        Git安装与问题
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.269009d6.js" defer></script><script src="/assets/js/3.974b9720.js" defer></script><script src="/assets/js/15.0a4ff48f.js" defer></script>
  </body>
</html>
